package com.sikao.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.adapter.MyFragmentPagerAdapter;
import com.sikao.app.fragment.MyMailFragment;
import com.sikao.app.ui.base.BaseActivity;

import java.util.ArrayList;

/**
 * 我的站内信模块
 */
public class MyMailActivity extends BaseActivity implements View.OnClickListener{

	private TextView titleTv;
	private ImageView backIv;
	private TextView sendMailTv;

	private ViewPager mPager;
	private ArrayList<Fragment> fragmentList;
	private TabLayout tabLayout;
	private String[] tabTitles = {"收到的站内信", "发送的站内信"};
	public static final String MY_SENT_MAILS = "mySentMails";
	public static final String MY_RECEIVED_MAILS = "myReceivedMails";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_my_mail);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void initData() {

	}

	@Override
	protected void initView() {
		titleTv = (TextView) findViewById(R.id.title_middle_tv);
		backIv = (ImageView) findViewById(R.id.title_left_img);
		sendMailTv = (TextView) findViewById(R.id.title_right_tv);

		mPager = (ViewPager) findViewById(R.id.view_pager);
		tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
	}

	@Override
	protected void initListener() {
		backIv.setOnClickListener(this);
		sendMailTv.setOnClickListener(this);
	}

	@Override
	protected void init() {
		titleTv.setText("我的站内信");
		backIv.setVisibility(View.VISIBLE);
		sendMailTv.setText("发布");
		sendMailTv.setVisibility(View.VISIBLE);

		initFragment();
		tabLayout.setupWithViewPager(mPager);
		tabLayout.setTabMode(TabLayout.MODE_FIXED);
	}

	private void initFragment() {
		mPager.setOffscreenPageLimit(1);
		fragmentList = new ArrayList<Fragment>();
		Fragment oneFragment = new MyMailFragment();
		Fragment twoFragment = new MyMailFragment();
		Bundle bundle1 = new Bundle();
		bundle1.putString("from",MY_SENT_MAILS);
		Bundle bundle2 = new Bundle();
		bundle2.putString("from",MY_RECEIVED_MAILS);
		oneFragment.setArguments(bundle1);
		twoFragment.setArguments(bundle2);
		fragmentList.add(twoFragment);
		fragmentList.add(oneFragment);

		mPager.setAdapter(new MyFragmentPagerAdapter(
				getSupportFragmentManager(), fragmentList,tabTitles));
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()){
			case R.id.title_left_img:
				finish();
				break;
			case R.id.title_right_tv:
				Intent intent = new Intent(MyMailActivity.this,SendMailActivity.class);
				startActivity(intent);
				break;
			default:
				break;
		}
	}

}
